<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="时间">
        <el-date-picker
          v-model="daterangeTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="出入库标志" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择出入库标志" clearable>
          <el-option
            v-for="dict in dict.type.InOutRecord"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="分段订单" prop="jcLedCode">
        <el-input
          v-model="queryParams.jcLedCode"
          placeholder="请输入分段订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['order:inoroutrecord:edit']"
        >查看</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['order:inoroutrecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="inoroutrecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" fixed/>
      <el-table-column label="组织机构" align="center" prop="jcOrganizationName" />
      <el-table-column label="库位" align="center" prop="jcZoneStoreroomName" />
      <el-table-column label="分段订单号" align="center" prop="jcLedCode" />
      <el-table-column label="出入库标志" align="center" prop="type">
        <template #default="scope">
          <dict-tag :options="dict.type.InOutRecord" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="时间" align="center" prop="time" width="180" />
      <el-table-column label="数量" align="center" prop="number" />
      <el-table-column label="体积" align="center" prop="volume" />
      <el-table-column label="重量" align="center" prop="weight" />
      <el-table-column label="创建人" align="center" prop="createName" />
      <el-table-column label="备注" align="center" prop="description" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改出入库记录对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">





        <el-form-item label="组织机构" prop="jcOrganizationName">
          <el-input v-model="form.jcOrganizationName" placeholder="请输入组织机构ID" />
        </el-form-item>
        <el-form-item label="库位" prop="jcZoneStoreroomName">
          <el-input v-model="form.jcZoneStoreroomName" placeholder="请输入库位" />
        </el-form-item>
        <el-form-item label="分段订单" prop="jcLedCode">
          <el-input v-model="form.jcLedCode" placeholder="请输入分段订单ID" />
        </el-form-item>
        <el-form-item label="出入库标志" prop="type">
          <el-select clearable v-model="form.type" placeholder="请选择出入库标志">
            <el-option
              v-for="dict in dict.type.InOutRecord"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="时间" prop="time">
          <el-date-picker clearable
                          v-model="form.time"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="数量" prop="number">
          <el-input v-model="form.number" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="体积" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入体积" />
        </el-form-item>
        <el-form-item label="重量" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入重量" />
        </el-form-item>
        <el-form-item label="备注" prop="description">
          <el-input v-model="form.description" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInoroutrecord, getInoroutrecord, updateInoroutrecord } from "@/api/order/inoroutrecord";

export default {
  name: "Inoroutrecord",
  dicts: ['InOutRecord'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出入库记录表格数据
      inoroutrecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 库位时间范围
      daterangeCreateTime: [],
      // 库位时间范围
      daterangeModifyTime: [],
      // 库位时间范围
      daterangeTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createName: null,
        description: null,
        number: null,
        time: null,
        type: null,
        volume: null,
        weight: null,
        jcLedCode: null,
        jcOrderId: null,
        jcOrganizationName: null,
        jcZoneStoreroomName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询出入库记录列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      if (null != this.daterangeModifyTime && '' != this.daterangeModifyTime) {
        this.queryParams.params["beginModifyTime"] = this.daterangeModifyTime[0];
        this.queryParams.params["endModifyTime"] = this.daterangeModifyTime[1];
      }
      if (null != this.daterangeTime && '' != this.daterangeTime) {
        this.queryParams.params["beginTime"] = this.daterangeTime[0];
        this.queryParams.params["endTime"] = this.daterangeTime[1];
      }
      listInoroutrecord(this.queryParams).then(response => {
        this.inoroutrecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createName: null,
        createTime: null,
        description: null,
        modifyName: null,
        modifyTime: null,
        name: null,
        status: null,
        number: null,
        time: null,
        type: null,
        volume: null,
        weight: null,
        jcLedCode: null,
        jcOrderId: null,
        jcOrganizationName: null,
        jcZoneStoreroomName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.daterangeModifyTime = [];
      this.daterangeTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInoroutrecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改出入库记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInoroutrecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('order/inoroutrecord/export', {
        ...this.queryParams
      }, `inoroutrecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
